package com.ld.security.server.blog.modules.cms.api;

import com.ld.security.auth.shiro.util.LoginUtil;
import com.ld.security.common.core.util.StringUtil;
import com.ld.security.common.mybatis.base.po.EntityPo;
import com.ld.security.common.mybatis.base.po.PagePo;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.mybatis.base.vo.PageVo;
import com.ld.security.common.tomcat.anno.AjaxLogKey;
import com.ld.security.common.tomcat.base.api.SuperApi;
import com.ld.security.server.blog.modules.cms.entity.CmsCollectEntity;
import com.ld.security.server.blog.modules.cms.service.ICmsCollectService;
import com.ld.security.server.blog.modules.cms.vo.AuthCollectionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


@RestController
@Api(tags="内容合集Api管理")
@RequestMapping("/api/cmsCollect")
public class CmsCollectApi  extends SuperApi<CmsCollectEntity>{

        @Autowired
        private ICmsCollectService iCmsCollectService;

    @AjaxLogKey
        @Override
        public DataVo save(@RequestBody @Valid EntityPo<CmsCollectEntity> po) {
    if (StringUtil.isNull(po.getEntity().getAuthorId())) {
            po.getEntity().setAuthorId(LoginUtil.getUserId());

    }
                return super.save(po);
        }

    @AjaxLogKey
        @RequestMapping(value = "pageAuthCollection",method = RequestMethod.POST)
        @ApiOperation("分页查询授权专辑")
        public DataVo pageAuthCollection(@RequestBody @Valid PagePo<AuthCollectionVo> po) {
                String id = LoginUtil.getUserId();

                po.getQuery().setUserId(id);
                PageVo vo =  iCmsCollectService.getAuthCollection(po);
                return DataVo.of(vo);
        }
}
